//
//  SEGPgcRecommendModel.m
//  FrameworkTest
//
//  Created by 刘山 on 2018/4/18.
//  Copyright © 2018年 刘山. All rights reserved.
//

//#if __has_include(<Commom/SEGToolsHeader.h>)
//#import <Commom/SEGToolsHeader.h>
//#else
//#import "SEGToolsHeader.h"
//#endif

#import <Masonry/Masonry.h>

#if __has_include(<Commom/SEGLayoutMacro.h>)
#import <Commom/SEGLayoutMacro.h>
#else
#import "SEGLayoutMacro.h"
#endif

#if __has_include(<Commom/SEGColorManager.h>)
#import <Commom/SEGColorManager.h>
#else
#import "SEGColorManager.h"
#endif

#import "SEGPgcRecommendModel.h"
#import <objc/runtime.h>

#import <Commom/NSObject+SEGModel.h>

@implementation SEGCommentModel
- (void)encodeWithCoder:(NSCoder *)encoder
{
    unsigned int count = 0;
    objc_property_t *propertes = class_copyPropertyList([self class], &count);
    for (int i=0; i<count; i++) {
        const char *propertyName = property_getName(propertes[i]);
        NSString *name = [NSString stringWithUTF8String:propertyName];
        id value = [self valueForKey:name];
        [encoder encodeObject:(value)?value:@"" forKey:name];
    }
}

- (id)initWithCoder:(NSCoder *)decoder
{
    if (self = [super init]) {
        unsigned int count =0;
        objc_property_t *propertes = class_copyPropertyList([self class], &count);
        for (int i = 0; i < count; i++) {
            const char *propertyName = property_getName(propertes[i]);
            NSString *name = [NSString stringWithUTF8String:propertyName];
            id value = [decoder decodeObjectForKey:name];
            [self setValue:(value)?value:@"" forKey:name];
        }
        
    }
    return self;
}

-(NSString *)description{
    return [self yy_modelDescription];
    
}
@end

@implementation SEGPgcRecommendModel
-(instancetype)init{
    if (self == [super init]) {
        _title = @"";//标题
        _objId = @"";
        _pic = [NSArray array];
        _channelName = @"";//频道名称
        _likeItTotal = @"";//喜欢数
        _commentTotal = @"";//评论数
        _pgcType = @"";//1：文字话题 2：图文话题
        _pgcId = @"";//主键
        _objType = SEGEnumNameObjType_PGC;//数据类型
        _pictorialStyle = @"";//板式：大一图、小三图....
        _linkMode = @"";//连接方式:SEGEnumLinkModeType
        _linkModules = @"";//连接方式 0网页链接 1图片链接 2内部链接
        _linkDetail = @"";//详细业务的id
        _url = @"";
        _comment = [NSArray array];
        _adverIndex = 0;
    }
    return self;
}

+ (NSDictionary *)modelContainerPropertyGenericClass {
    return @{@"comment" : SEGCommentModel.class,
             @"pic" : [NSString class]
             };
}

- (void)encodeWithCoder:(NSCoder *)encoder
{
    unsigned int count = 0;
    objc_property_t *propertes = class_copyPropertyList([self class], &count);
    for (int i=0; i<count; i++) {
        const char *propertyName = property_getName(propertes[i]);
        NSString *name = [NSString stringWithUTF8String:propertyName];
        id value = [self valueForKey:name];
        [encoder encodeObject:(value)?value:@"" forKey:name];
    }
}

- (id)initWithCoder:(NSCoder *)decoder
{
    if (self = [super init]) {
        unsigned int count =0;
        objc_property_t *propertes = class_copyPropertyList([self class], &count);
        for (int i = 0; i < count; i++) {
            const char *propertyName = property_getName(propertes[i]);
            NSString *name = [NSString stringWithUTF8String:propertyName];
            id value = [decoder decodeObjectForKey:name];
            if ([name isEqualToString:@"adverIndex"] && !value) {
                continue;
            }
            [self setValue:(value)?value:@"" forKey:name];
        }
        
    }
    return self;
}

-(NSString *)description{
    return [self yy_modelDescription];
    
}
 
- (NSString *)firstImageURL {
    if (self.pic.count > 0) {
        return [NSString stringWithFormat:@"%@%@", kClientImageRootURL, self.pic.firstObject];
    }
    return @"";
}

@end
 
